#coding:utf-8
import requests
import lxml
import re
import time
from selenium import webdriver
from bs4 import BeautifulSoup
import json

def select_course(r):
    r3 = r.get("http://202.115.47.141/student/courseSelect/courseSelect/index",headers=headers)
    soup = BeautifulSoup(r3.text,'lxml',from_encoding='utf-8')
    info_back = soup.select("div[class='alert alert-block alert-danger']")[0]
    print(info_back)

def init_sys(stuNum,passWord):
    data = {"j_captcha1":"error","j_password":passWord,"j_username":stuNum}
    headers = {"User-Agent":"Mozilla/5.0(Windows NT 10.0;x64;rv:62.0)Gecho/20100101 Firefox/62.0","Referer":"http://202.115.47.141/login"}
    r = requests.Session()
    r1 = r.post("http://202.115.47.141/j_spring_security_check",headers=headers,data=data)
    return r,headers

def course_table(r,headers):
    #r2 = r.get("http://202.115.47.141/student/courseSelect/thisSemesterCurriculum/index",headers=headers)
    r2 = r.get("http://202.115.47.141/student/courseSelect/thisSemesterCurriculum/ajaxStudentSchedule/callback",headers=headers)
    r2.encoding='utf-8'
    json_data = json.loads(r2.text)
    #print(json_data["xkxx"][0])
    print('className\t\t\tclassadress\t\tweekDescription')
    for item in json_data["xkxx"][0]:
    	print(json_data["xkxx"][0][item]['timeAndPlaceList'][0]['coureName'],'\t\t\t',\
            json_data["xkxx"][0][item]['timeAndPlaceList'][0]['teachingBuildingName'],\
            json_data["xkxx"][0][item]['timeAndPlaceList'][0]['classroomName'],'\t\t',\
            json_data["xkxx"][0][item]['timeAndPlaceList'][0]['weekDescription'])

if __name__ == "__main__":
    stuNum = input('please input your stuNum:')
    passWord = input('please input your passWord:')
    r,headers = init_sys(stuNum,passWord)
    while True:
        choice = int(input('1.select your classTable\n2.auto select classes\n3.exit\nplease input your choice:'))
        if choice == 1:
            course_table(r,headers)
        elif choice == 2:
            select_course(r)
        elif choice == 3:
            break
        else:
            print('your input is wrong!')